<?php
/**
 * @package    panel
 * @subpackage panel.environment
 */

	/**
	 * Shorcut to Panel
	 * @author Dmitry Bakaleinik (code)
	 * @return panel
	 */
	function p() {

		return panel::getInstance();

	}	# Function

	/**
	 * Check value using defined
	 * @throws panel__e__validation
	 * @param mixed $_value_
	 * @param string $_name_ "Field/Variable name"
	 * @author Dmitry Bakaleinik (code)
	 * @return mixed {&$_value_}
	 */
	function p_defined(&$_value_, $_name_ = NULL) {

		/**
		 * Detect variable name
		 */
		if( is_null($_name_) ) {

		try {

			$trace    = debug_backtrace();
			$includes = array("include", "include_once", "require", "require_once");

			for( $I = count($trace) - 1; $I >= 0; $I-- ) {

				$current = $trace[$I];

				if(
					array_key_exists("function", $current) &&
					(
						in_array($current["function"], $includes) ||
						(0 != strcasecmp($current["function"], __FUNCTION__))
					)
				) {

					continue;

				}	# if

				$file = $current;

			}	# for

			if( isset($file) ) {

				$lines = file($file["file"]);
				$code  = $lines[($file["line"] - 1)];

				preg_match('/\b' . __FUNCTION__ . '\s*\(\s*(.+)\s*\);/i', $code, $matches);
				$_name_ = isset_or($matches[1]);

			}	# if

		} catch( exception $e ) { }

		}	# if

		/**
		 * Validate
		 */
		return panel__validate::check($_value_, "defined!", $_name_);

	}	# Function

/* EOF */